const cloud = require('wx-server-sdk');

const db = cloud.database()

exports.main = async (event,context)=>{
	let searchData = {}
	if(event.openid!=undefined){
	 searchData['shortcode']= event.openid
	}
	if(event.isVideo){
		searchData.is_video = 1;
	}
  let edgeInfos = await db.collection('user_edge').where(searchData).orderBy('taken_at_timestamp','desc').limit(15).skip(event.start*15).get();
  let all_data = [...edgeInfos.data]
  if(all_data.length<15){
    let stores = await db.collection('store').where(searchData).orderBy('taken_at_timestamp','desc').limit(15).skip(event.start*15).get();
    all_data.push(...stores.data)
  }
	return {'msg':'ok','data':all_data}
}